<?php
/**
 * Created by PhpStorm.
 * User: x
 * Date: 2018/10/27
 * Time: 15:03
 */

namespace app\api\controller;

use app\common\controller\HomeBase;
use app\common\model\Kefu as KefuModel;
use app\common\model\Csuser as CsuserModel;
// 常用回复
use app\common\model\Csuserwords as CsWordsModel;
use app\common\model\AuthorWxUser as AuthorWxUserModel;
use think\Session;
use app\common\model\Users as UsersModel;

class Fans extends HomeBase{
    protected $users_model;
    protected function _initialize()
    {
        parent::_initialize();
        $this->author_config = session::get('wechat_info');
        $this->users_model = new UsersModel();
    }

    /*
     * 获取所有粉丝
     * */
    public function all($start_time = '',$end_time = '',$page = 1,$keyword = ''){
        $where = [];
        if(!empty($start_time) && !empty($end_time)){
            $where = [
                'subscribe_time'=>['between',[$start_time,$end_time]],
            ];
        }
        if (!empty($keyword)) {
            $where['think_users.nickname'] = ['like','%'.$keyword.'%'];
        }
        $where['think_users.auid'] = ['eq',$this->author_config['id']];
        $result = $this->users_model
            ->field('u.butt_id,u.sex,u.subscribe_time,u.unsubscribe_time,u.subscribe,u.openid,u.headimgurl,u.nickname,think_csuser.nickname as cs_nickname')
            ->alias('u')
            ->join('think_csuser','u.butt_id = think_csuser.id','left')
            ->where($where)
            ->order('subscribe_time desc')
            ->paginate(15,false,['page'=>$page]);
        return json(['status' => 1,'data' => $result, 'key'=> [
            'keyword' => $keyword,
            'page' => $page,
            'start_time' => $start_time,
            'end_time' => $end_time
        ]]);
    }
}